package com.example.myapplication.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.myapplication.R;

public class ButtonView2 extends RelativeLayout {

    private ImageButton btn;
    private FrameLayout notice;
    private TextView num;
    private TextView name;

    private int actIco;
    private int deActIco;
    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.btn_item2, this);
        btn = findViewById(R.id.btn);
        notice = findViewById(R.id.notice);
        num = findViewById(R.id.num);
        name = findViewById(R.id.txt);

        btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                performClick();
            }
        });
    }


    public ButtonView2(Context context) {
        super(context);
        init();
    }

    public ButtonView2(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public void setBtnName(String val)
    {
        name.setText(val);
    }
    public void setMsgCount(int n)
    {
        if(n>0) {
            num.setText(n>99 ? "..." : String.valueOf(n));
            notice.setVisibility(VISIBLE);
        } else {
            notice.setVisibility(GONE);
        }
    }

    public void setActivateIco(int id) {
        actIco = id;
    }

    public void setDeactivateIco(int id) {
        deActIco = id;
    }

    public void setChecked(boolean isChecked) {
        btn.setImageResource(isChecked ? actIco : deActIco);
        name.setTextColor(isChecked ? getResources().getColor(R.color.green) :getResources().getColor(R.color.text_gray));
    }


}
